package com.yanchangapp.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.IBinder;
import android.support.annotation.NonNull;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

/**
 * Created by apple on 2019-09-06.
 * description:自定义带输入框的dialog
 *
 * 在其结束前 进行输入框的关闭.....
 */
public class InputDialog extends Dialog {
    private Context mContext;

    public InputDialog(@NonNull Context context) {
        this(context,0);
    }

    public InputDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        mContext = context;
    }

    @Override
    public void dismiss() {
        InputMethodManager imm = (InputMethodManager) mContext.getApplicationContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        // 即使当前焦点不在editText，也是可以隐藏的。
        if (imm != null) {
            final View currentFocus = getCurrentFocus();
            IBinder windowToken = null;
            if (currentFocus != null) {
                windowToken = currentFocus.getWindowToken();
            }
            if (windowToken != null) {
                imm.hideSoftInputFromWindow(windowToken, 0);
            }
        }
        super.dismiss();
    }
}
